﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;

namespace WMI.NET.CIM
{
    /// <summary>
    /// The CIM_MediaAccessDevice class represents the ability to access one or more media, and then use the media to store and retrieve data.
    /// </summary>
    public class CIM_MediaAccessDevice : CIM_LogicalDevice
    {
        private ushort[] _Capabilities;
        private string[] _CapabilityDescriptions;
        private string _CompressionMethod;
        private Nullable<UInt64> _DefaultBlockSize;
        private string _ErrorMethodology;
        private Nullable<UInt64> _MaxBlockSize;
        private Nullable<UInt64> _MaxMediaSize;
        private Nullable<UInt64> _MinBlockSize;
        private Nullable<Boolean> _NeedsCleaning;
        private Nullable<UInt32> _NumberOfMediaSupported;


        /// <summary>
        /// Capabilities of the media access device. 
        /// </summary>
        public UInt16[] Capabilities { get { return _Capabilities; } } //TODO Enum

        /// <summary>
        /// Array of free-form strings that provides detailed explanations for access device features indicated in the Capabilities array.
        /// Note   Each entry of this array is related to the entry in the Capabilities array, located at the same index.
        /// </summary>
        public string[] CapabilityDescriptions { get { return _CapabilityDescriptions; } }

        /// <summary>
        /// Free-form string that indicates the algorithm or tool used to compress the logical file. If the compression scheme is unknown or not described, use "Unknown". If the logical file is compressed, but the compression scheme is unknown or not described, use "Compressed". If the logical file is not compressed, use "Not Compressed". 
        /// </summary>
        public string CompressionMethod { get { return _CompressionMethod; } }

        /// <summary>
        /// Default block size, in bytes, for the device.
        /// </summary>
        public Nullable<UInt64> DefaultBlockSize { get { return _DefaultBlockSize; } }

        /// <summary>
        /// Free-form string that describes the types of error detection and correction supported by the device.
        /// </summary>
        public string ErrorMethodology { get { return _ErrorMethodology; } }

        /// <summary>
        /// Maximum block size, in bytes, for media accessed by the device.
        /// </summary>
        public Nullable<UInt64> MaxBlockSize { get { return _MaxBlockSize; } }

        /// <summary>
        /// Maximum size, in kilobytes, of media supported by this device. Kilobytes are interpreted as the number of bytes multiplied by 1000 (not the number of bytes multiplied by 1024).
        /// </summary>
        public Nullable<UInt64> MaxMediaSize { get { return _MaxMediaSize; } }

        /// <summary>
        /// Minimum block size, in bytes, for media accessed by the device.
        /// </summary>
        public Nullable<UInt64> MinBlockSize { get { return _MinBlockSize; } }

        /// <summary>
        /// If TRUE, the media access device needs cleaning. Whether manual or automatic cleaning is possible is indicated in the Capabilities array property.
        /// </summary>
        public Nullable<Boolean> NeedsCleaning { get { return _NeedsCleaning; } }

        /// <summary>
        /// Maximum number of multiple individual media that can be supported or inserted.
        /// </summary>
        public Nullable<UInt32> NumberOfMediaSupported { get { return _NumberOfMediaSupported; } }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="mbo"></param>
        public CIM_MediaAccessDevice(ManagementBaseObject mbo)
            : base(mbo)
        {
            _Capabilities = mbo.GetUshortValueArray("Capabilities");
            _CapabilityDescriptions = mbo.GetStringValueArray("CapabilityDescriptions");
            _CompressionMethod = mbo.GetStringValue("CompressionMethod");
            _DefaultBlockSize = mbo.GetUlongValue("DefaultBlockSize");
            _ErrorMethodology = mbo.GetStringValue("ErrorMethodology");
            _MaxBlockSize = mbo.GetUlongValue("MaxBlockSize");
            _MaxMediaSize = mbo.GetUlongValue("MaxMediaSize");
            _MinBlockSize = mbo.GetUlongValue("MinBlockSize");
            _NeedsCleaning = mbo.GetBoolValue("NeedsCleaning");
            _NumberOfMediaSupported = mbo.GetUIntValue("NumberOfMediaSupported");
        }

    }
}
